package com.junlong0716.enjoylearning.adapter

import com.blankj.utilcode.util.TimeUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.htxcsoft.corelibrary.glide.GlideUtils
import com.junlong0716.enjoylearning.MyApp
import com.junlong0716.enjoylearning.R
import com.junlong0716.enjoylearning.constant.NetConstant.REQUEST_SOURCE
import com.junlong0716.enjoylearning.entity.CommentEntity

/**
 *@author: 巴黎没有摩天轮Li
 *@description:
 *@date: Created in 下午1:29 2018/5/5
 *@modified by:
 */
class CommentAdapter(data: ArrayList<CommentEntity.DataBean.ListBean>, resLayout: Int) : BaseQuickAdapter<CommentEntity.DataBean.ListBean, BaseViewHolder>(resLayout, data) {
    override fun convert(helper: BaseViewHolder?, item: CommentEntity.DataBean.ListBean?) {
        GlideUtils.showImage(mContext, REQUEST_SOURCE + item!!.headImg, helper!!.getView(R.id.civ_avatar), R.mipmap.ic_avatar_man)
        helper.setText(R.id.tv_nickname, item.userName)
        helper.setText(R.id.tv_comment_content, item.commentContent)
        helper.setText(R.id.tv_comment_time, TimeUtils.millis2String(item.createDate))

        if (item.isPraise == 0){
            helper.addOnClickListener(R.id.ll_love_container)
            helper.setBackgroundRes(R.id.iv_love,R.mipmap.ic_love_unsel)
            helper.setText(R.id.tv_love_num,item.praiseNumber.toString())
        }else if (item.isPraise == 1){
            //helper.addOnClickListener(R.id.ll_love_container)
            helper.setBackgroundRes(R.id.iv_love,R.mipmap.ic_love_sel)
            helper.setText(R.id.tv_love_num,item.praiseNumber.toString())
        }

        if (item.userId == MyApp.instance().userAccount!!.id){
            helper.setVisible(R.id.tv_delete,true)
            helper.addOnClickListener(R.id.tv_delete)
        }else{
            helper.setVisible(R.id.tv_delete,false)
        }

    }
}